package com.xiaozhu.pojo;

import lombok.Data;

/**
 * @author 朱慧军
 * @version 1.0
 *
 * 统一响应类
 */

@Data
public class Result <T> {

    /**
     * 1: 代表成功ture
     * 0： 代表失败false
     */
    private int code;
    private String msg;
    private Object data;

    /**
     * 响应成功
     * @param data
     * @return
     */
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(1);
        result.setData(data);
        result.setMsg("success");
        return result;
    }

    public static Result success() {
        Result result = new Result();
        result.setCode(1);
        result.setMsg("success");
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg("失败");
        return result;
    }

    public static Result error(int code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result error() {
        Result result = new Result();
        result.setCode(0);
        return result;
    }
}
